package com.ymatou.iapi.dguser.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.DistributorDto;
import com.ymatou.iapi.dguser.parameter.QueryDistributorBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.dguser.service.QueryDistributorCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.utils.TestDataManager;
/**
*分销员查询
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryDistributor{
	private static QueryDistributorBean querydistributorBean;
	private static QueryDistributorCall querydistributorCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("分销员查询");
	}

	@Before
	public void caseUp() {
		querydistributorBean=new QueryDistributorBean();
		querydistributorCall=new QueryDistributorCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querydistributorCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryDistributor_001() {
		Logger.start(true,"分销员查询成功");
		try {
			Integer shopId=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			usercreateBean.setShopId(shopId);
			usercreateBean.setMobile(mobile);
			usercreateBean.setUserType(3);
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			
			querydistributorBean.setMobile(mobile);
			querydistributorBean.setShopId(shopId);
			querydistributorCall.setData(querydistributorBean);
			querydistributorCall.callService();			
			//{"success":true,"distributorDto":{"userId":501103985,"mobile":"13403306106","nickname":"NickautoTest","loginId":"c9031f2247504f6b895638057446c13b","userType":3,"userStatus":0}}
			Logger.verifyEquals("true", querydistributorCall.getString("success"), "验证success");
			DistributorDto dd = querydistributorCall.getDistributorDto();
			Logger.verifyEquals(userId, dd.getUserId(), "验证userid");
			Logger.verifyEquals(mobile, dd.getMobile(), "验证getMobile");
			Logger.verifyEquals(usercreateBean.getNickname(), dd.getNickname(), "验证getNickname");
			Logger.verifyEquals(0, dd.getUserStatus(), "验证getUserStatus");
			Logger.verifyEquals(3, dd.getUserType(), "验证getUserType");
			Logger.verifyNotNull(dd.getLoginId(),"验证getLoginId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryDistributor_002() {
		Logger.start(true,"不输入shopId失败");
		try {
			Integer shopId=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			querydistributorBean.setMobile(mobile);
//			querydistributorBean.setShopId(shopId);
			querydistributorCall.setData(querydistributorBean);
			querydistributorCall.callService();
			Logger.verifyEquals("false", querydistributorCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryDistributor_003() {
		Logger.start(true,"不输入mobile失败");
		try {
			Integer shopId=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
//			querydistributorBean.setMobile(mobile);
			querydistributorBean.setShopId(shopId);
			querydistributorCall.setData(querydistributorBean);
			querydistributorCall.callService();
			Logger.verifyEquals("false", querydistributorCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryDistributor_004() {
		Logger.start(true,"输入shopId和mobile不匹配失败");
		try {
			Integer shopId=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			usercreateBean.setShopId(shopId);
			usercreateBean.setMobile(mobile);
			usercreateBean.setUserType(3);
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			
			querydistributorBean.setMobile(mobile);
			querydistributorBean.setShopId(1);
			querydistributorCall.setData(querydistributorBean);
			querydistributorCall.callService();			
			//{"success":true,"distributorDto":{"userId":501103985,"mobile":"13403306106","nickname":"NickautoTest","loginId":"c9031f2247504f6b895638057446c13b","userType":3,"userStatus":0}}
			Logger.verifyEquals("true", querydistributorCall.getString("success"), "验证success");	
			Logger.verifyIsNull(querydistributorCall.getDistributorDto(), "验证getDistributorDto");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryDistributor_005() {
		Logger.start(true,"输入的不是分销员");
		try {
			Integer shopId=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			usercreateBean.setShopId(shopId);
			usercreateBean.setMobile(mobile);
//			usercreateBean.setUserType(3);
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			
			querydistributorBean.setMobile(mobile);
			querydistributorBean.setShopId(shopId);
			querydistributorCall.setData(querydistributorBean);
			querydistributorCall.callService();		
			Logger.verifyEquals("true", querydistributorCall.getString("success"), "验证success");
			Logger.verifyIsNull(querydistributorCall.getDistributorDto(), "验证getDistributorDto");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}